﻿using System;
using System.Windows.Controls;
using ShadeTree.Binding.Elements;

namespace ShadeTree.Binding.WPF
{
    public class CheckboxElement : BoundScreenElement<CheckBox, bool>
    {
        public CheckboxElement(Accessor accessor, CheckBox control) : base(accessor, control)
        {
            control.Checked += control_CheckedChanged;
            control.Unchecked += control_CheckedChanged;

            Alias = control.Content as string;
        }

        private void control_CheckedChanged(object sender, EventArgs e)
        {
            elementValueChanged();
        }


        protected override bool getValueFromControl()
        {
            return BoundControl.IsChecked.GetValueOrDefault(false);
        }

        protected override void resetControl(bool originalValue)
        {
            BoundControl.IsChecked = originalValue;
        }

        protected override void tearDown()
        {
            BoundControl.Checked -= control_CheckedChanged;
            BoundControl.Unchecked -= control_CheckedChanged;
        }
    }
}